﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Traceability.Domain.Users;
using Traceability.Repository;
using Traceability.Services;

namespace Traceability.Services.UserServices
{
    /// <summary>
    /// 用户服务
    /// </summary>
    public class AccountService:IAccountService

    {
        private readonly IBaseRepository<Account> _accountbaseRepository;

        public AccountService(IBaseRepository<Account> accountbaseRepository)
        {
            _accountbaseRepository = accountbaseRepository;
        }


        public async Task<APIResult<Account>> Login(string username, string password)
        {
            var account = await _accountbaseRepository.GetAsync(a=>a.AccountName==username);
            if (account == null)
            {
                return new APIResult<Account>()
                {
                    Code = EnumCode.Fail,
                    Msg = "用户名错误"
                }; 
            }
           
            if (account.AccountPass != password)
            {
                return new APIResult<Account>()
                {
                    Code = EnumCode.Fail,
                    Msg = "密码错误"
                };
            }

            return new APIResult<Account>()
            {
                Data = account,
                Code = EnumCode.Success,
                Msg = "登录成功"
            };
        }
    }
}
